﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using pttk_htt_hr.Constant;
using pttk_htt_hr.DTO;

namespace pttk_htt_hr.DAO
{
    class ThucDonDAO
    {
        #region Select
        public static ThucDonDTO Get_ThucDon(List<SqlParameter> parameters)
        {
            DBMS dbms = new DBMS();
            dbms.Connect();
            ThucDonDTO td = new ThucDonDTO();

            DataTable dt = dbms.ExcuteProcedure_Select_DataTable(StoreProcedureConstant.SP_SELECT_THUC_DON_ById, parameters.ToArray());
            DataRow dr = dt.Rows[0];

            td.MaTD = dr[TableColumnMapping.MaTD].ToString();
            td.TenTD = dr[TableColumnMapping.TenTD].ToString();
            
            dbms.Disconnect();
            return td;
        }
        /// <summary>
        /// MĐ: Lấy danh sách thực đơn, không điều ki
        /// </summary>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public static List<Dictionary<string, string>> Get_List(List<SqlParameter> parameters, bool hasConds)
        {
            DBMS dbms = new DBMS();
            dbms.Connect();

            List<Dictionary<string, string>> LstDic = new List<Dictionary<string, string>>();
           
            DataTable dt;
            if (hasConds)
            {
                dt = dbms.ExcuteProcedure_Select_DataTable(StoreProcedureConstant.SP_SELECT_THUC_DON_ByConds, parameters.ToArray());
            }
            else
            {
                dt = dbms.ExcuteProcedure_Select_DataTable(StoreProcedureConstant.SP_SELECT_THUC_DON, parameters.ToArray());
            }

            

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                Dictionary<string, string> row = new Dictionary<string, string>();

                row.Add(TableColumnMapping.MaTD, dr[TableColumnMapping.MaTD].ToString());
                row.Add(TableColumnMapping.TenTD, dr[TableColumnMapping.TenTD].ToString());

                // Add to list
                LstDic.Add(row);
            }

            dbms.Disconnect();

            return LstDic;
        }

        
        #endregion

        #region Insert
        #endregion

        #region Update
        #endregion

        #region Delete
        #endregion    
    }
}
